package fair.utils;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;

/**
 * @author fair_wu
 * @version v1.0
 * @package fair.utils
 * @date 2021-01-28 下午 15:50
 */
public class TXSMSUtils {
    public static final String SecretId = "AKID6k8F5dxvgBTVJN6hyThdJbcLp3zHN2Ug";// 你的SecretId
    public static final String SecretKey = "4uTlmVYKp21j24pIUPimZ4IG1U2JI2Vg";// 你的SecretKey
    public static final String SDKAppID = "1400479726";// 你的accessKeySecret
    public static final String VALIDATE_CODE = "857382";//发送短信验证码
    public static final String ORDER_NOTICE = "857708";//体检预约成功通知

    public static void sendShortMessage(String phone, String templateCode, String templateParam){
        Credential cred = new Credential(SecretId, SecretKey);

        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("sms.tencentcloudapi.com");

        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);

        SmsClient client = new SmsClient(cred, "", clientProfile);
        SendSmsRequest req = new SendSmsRequest();
        String[] phones = new String[] {"+86" + phone};
        String[] templateParams = new String[] {templateParam};

        req.setSmsSdkAppid(SDKAppID);
        req.setPhoneNumberSet(phones);
        req.setTemplateID(templateCode);
        req.setTemplateParamSet(templateParams);
        req.setSign("景涛的公众号");

        try {
            SendSmsResponse response = client.SendSms(req); //发送短信
            System.out.println(SendSmsResponse.toJsonString(response));
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
        }
    }
}
